/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.bean.model.CouponRecord;
import com.yami.shop.security.util.SecurityUtils;
import com.yami.shop.service.CouponRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author lgh on 2018/10/16.
 */
@Api(tags = "优惠券接口")
@RestController
@RequestMapping("/p/coupon")
public class CouponRecordController {

    @Autowired
    private CouponRecordService couponRecordService;

    @GetMapping("/history")
    @ApiOperation(value = "查看某人的优惠券记录")
    public ResponseEntity get() {
        String userId = SecurityUtils.getUser().getUserId();
        LambdaQueryWrapper<CouponRecord> query = Wrappers.lambdaQuery(new CouponRecord())
                .eq(CouponRecord::getUid, userId)
                .orderByDesc(CouponRecord::getCreateTime);
        List<CouponRecord> list = couponRecordService.list(query);

        return ResponseEntity.ok(list);
    }


}
